package www.ld.com.utils;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import www.ld.com.domain.vo.PageRestVO;

import java.util.List;
import java.util.stream.Collectors;

public class PageUtils<T> {
    private PageUtils() {

    }
    public static<T> PageRestVO copyPageVO(IPage iPage, Class<T>  target) {
        List<Object> records = iPage.getRecords();
        List<T> recordsVO = records.stream().map((v) -> BeanUtil.toBean(v, target)).collect(Collectors.toList());
        return new PageRestVO<T>(iPage.getPages(),iPage.getTotal(), iPage.getCurrent(), iPage.getSize(),recordsVO);
    }
}
